package com.hspedu.homework.homework08;

/**
 * @Author Stringzhua
 * @Date 2024/3/3 18:46
 * description:扩展新类SavingAccount每个月都有利息产生(earnMonthlyInterest方法被调用),
 * 并且有每月三次免手续费的存款或取款
 * 在earnMonthlyInterest方法中重置交易的计数
 */
public class SavingAccount extends BankAccount {
    //新增属性
    private int count = 3;//交易次数
    private double rate = 0.01;//利率

    public void earnMonthlyInterest() {
        count = 3;//每个月初我们统计上个月的利息,同时将count设置成3
        super.deposit(getBalance() * rate);
    }

    //重写父类的相关方法
    //存款

    @Override
    public void deposit(double amount) {
        //判断是否还可以免手续费
        if (count > 0) {
            super.deposit(amount);
        } else {
            super.deposit(amount - 1);//把1美元转入银行账号
        }
        count--;//减去一次
    }
    //取款

    @Override
    public void withdram(double amount) {
        if (count > 0) {
            super.withdram(amount);
        } else {
            super.withdram(amount + 1);//把1美元转入银行账号
        }
        count--;//减去一次
    }


//构造器

    public SavingAccount(double initialBalance) {
        super(initialBalance);
    }

    //get\set方法
    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
}
